Skip to content

Conversation

@covertmatthew
Copy link

@covertmatthew covertmatthew commented Dec 11, 2025

What changed:

  • Replaced Boost Accumulators (and headers) with a lightweight, dependency-free implementation using Welford’s online algorithm for stable mean and variance calculation.
  • Introduced compile-time clock selection:
    • Prefer std::high_resolution_clock only if it is monotonic (is_steady == true).
    • Fallback to std::steady_clock for guaranteed monotonic behavior.
  • Updated confidence interval calculation:
    • Return (mean_ns, 95% CI half-width in ns) instead of a rough estimate.
    • Use z = 1.96 for normal approximation.
  • Increased default sample size from 100 → 1000 for better statistical stability.
  • Added filtering and safety checks:
    • Filter out unrealistic timer values (> 1 ms).
    • Terminate the program (std::exit) if fewer than 100 valid samples remain after filtering.
  • Improved comments and clarified output in p11perftest.cpp:
    • Print: "timer granularity (ns): mean ± (95% confidence interval)".

Why:

  • Ensures portable, accurate timing measurements across platforms.
  • Eliminates external dependency (Boost) for simpler maintenance.
  • Guarantees monotonic clock for reliable interval measurement.
  • Provides statistically meaningful confidence interval for precision reporting.
  • Adds robustness by filtering out invalid measurements and failing fast when data quality is insufficient.

Test (not bad for a VM):

[dc-user@ech-10-157-158-249 test]$ for i in {1..10}; do ./precision; sleep 1; done
timer granularity (ns): 69.514 +/- 3.91384
timer granularity (ns): 47.406 +/- 1.22714
timer granularity (ns): 48.027 +/- 1.07027
timer granularity (ns): 38.501 +/- 0.378576
timer granularity (ns): 49.323 +/- 0.501975
timer granularity (ns): 52.987 +/- 0.997222
timer granularity (ns): 40.877 +/- 0.705936
timer granularity (ns): 45.405 +/- 1.26509
timer granularity (ns): 44.501 +/- 0.635019
timer granularity (ns): 93.439 +/- 90.7611

@keldonin keldonin requested a review from Copilot December 12, 2025 01:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes timer precision measurement by removing the Boost Accumulators dependency and implementing Welford's online algorithm for stable statistical calculations. The changes ensure portable, monotonic timing across platforms with improved statistical rigor and better error handling.

Key changes:

  • Replaced Boost Accumulators with a custom implementation using Welford's algorithm for mean/variance calculation
  • Added compile-time clock selection to prefer high_resolution_clock only when monotonic, with fallback to steady_clock
  • Enhanced statistical accuracy by computing proper 95% confidence intervals (z=1.96) and increasing sample size from 100 to 1000

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/timeprecision.hpp Updated function signature to reflect new default sample size (1000) and documented filtering/termination behavior
src/timeprecision.cpp Replaced Boost implementation with Welford's algorithm, added clock selection logic, implemented value filtering with >1ms threshold, and added program termination for insufficient samples
src/p11perftest.cpp Enhanced output message to clarify that the interval represents a 95% confidence interval

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reset release tagging - I prefer to keep this in a separate commit. The 3.15.1 was a mistake and It will be corrected through PR #21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants